.TH std::ranges::split_view::begin 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ranges::split_view::begin \- std::ranges::split_view::begin

.SH Synopsis
   constexpr /*iterator*/ begin();  \fI(since C++20)\fP

   Returns an iterator to the first found subrange.

   In order to provide the amortized constant time complexity required by the range
   concept, this function caches the result within the split_view for use on subsequent
   calls. Equivalent to

 constexpr /*iterator*/ begin()
 {
     if (!cached_begin_.has_value())
         cached_begin_ = this->find_next(ranges::begin(base_));
     return {*this, ranges::begin(base_), cached_begin_.value()};
 }

   Exposition only data members base_ and cached_begin_ are described here.

.SH Parameters

   \fI(none)\fP

.SH Return value

   An iterator.

.SH Complexity

   Amortized \\(\\scriptsize \\mathcal{O}(1)\\)O(1).

.SH Example


// Run this code

 #include <iomanip>
 #include <iostream>
 #include <ranges>
 #include <string_view>

 int main()
 {
     constexpr std::string_view sentence{"Keep..moving..forward.."};
     constexpr std::string_view delim{".."};
     std::ranges::split_view words{sentence, delim};

     std::cout << "begin(): " << std::quoted(std::string_view{*words.begin()})
               << "\\nSubstrings: ";
     for (std::string_view word : words)
         std::cout << std::quoted(word) << ' ';

     std::ranges::split_view letters{sentence, std::string_view{""}};
     std::cout << "\\nbegin(): " << std::quoted(std::string_view{*letters.begin()})
               << "\\nLetters: ";
     for (std::string_view letter : letters)
         std::cout << letter << ' ';
     std::cout << '\\n';
 }

.SH Output:

 begin(): "Keep"
 Substrings: "Keep" "moving" "forward" ""
 begin(): "K"
 Letters: K e e p . . m o v i n g . . f o r w a r d . .

.SH See also

   end           returns an iterator or a sentinel to the end
   (C++20)       \fI(public member function)\fP
   begin         returns an iterator to the beginning
   (C++20)       \fI(public member function of std::ranges::lazy_split_view<V,Pattern>)\fP

   ranges::begin returns an iterator to the beginning of a range
   (C++20)       (customization point object)
